package view;

import dao.User;
import dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/addLogin")
public class AddLogin extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        //resp.setContentType("text/html;charset=utf-8");
        String userName = req.getParameter("userName");
        String passWord = req.getParameter("passWord");
        User user = new User();
        user.setUserName(userName);
        user.setPassWord(passWord);
        UserDao userDao = new UserDao();
        try {
            userDao.insert(user);
            resp.sendRedirect("login.html");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
